package com.example.demo.leetcode.top100;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _63搜索插入位置
 * @description
 * @date 2023/06/22 14:30
 * <p>
 * ******************************************************
 */
public class _63搜索插入位置 {

    public int searchInsert(int[] nums, int target) {

        int length = nums.length;

        int left = 0;
        int right = length - 1;
        int mid = 0;
        while (left <= right) {
            mid = right - (right - left) / 2;

            if (nums[mid] > target) {
                right = mid;
            }else if (nums[mid] < target) {
                left = mid + 1;
            } else {
                return mid;
            }
        }
        return left;
    }


}
